<template>
  <div class="card-container">
    <el-row :gutter="20">
        <el-col :span="12" :md="8" :lg="6" class="cc" v-for="o in appData" :key="o.id">
          <el-card :body-style="{ padding: '0px'}" shadow="hover" class="card">
            <el-button type="text" class="text-btn" @click="openApp(o.id)">
              <div class="card-img">
                <img :src="o.icon" class="image">
                <div></div>
              </div>
            </el-button>
            <div class="card-info">
              <el-button type="text" class="text-btn" @click="openApp(o.id)">
                <div class="title">{{o.name}}</div>
              </el-button>
              <div class="category">{{o.keywords}}
                <el-tag size="mini">{{o.namespaceName}}</el-tag>
              </div>
              <div class="version">版本：{{o.version}}
                <kt-button icon="fa fa-trash" title="卸载" :label="$t('action.empty')" :perms="permsDelete" type="info" size="mini" 
                :loading="editLoading" @click="appDelete(o.id)" />
              </div>
            </div>
          </el-card>
        </el-col>
    </el-row>
  </div>
</template>

<script>
import KtButton from "@/views/Core/KtButton"
export default {
  name: "KtSimpleCard",
  components:{
			KtButton
  },
  props: {
    permsDelete: String,
    appData: Array, // 应用列表数据
    deleteOk: Function
	},
  data() {
    return {
      checkAll: false,
      editLoading: false,
      isIndeterminate: true,
      checkedApps: [1, 3, 4],
      allApps: [1,2,3,4,5,6,7,8,9]
    };
  },
  methods: {
    openApp(appId){
      //TODO 打开应用的权限判断
      let routeData = this.$router.resolve({ path: '/app/' + appId});
      window.open(routeData.href, '_blank');
      // this.$api.apps.appRun(appId).then((res) => {
			// 	console.log(res);
			// 	this.editLoading = false
			// 	if(res.code == 200) {
      //     let routeData = this.$router.resolve({ path: '/app/' + appId});
			//     window.open(routeData.href, '_blank');
			// 	} else {
      //     this.$alert(res.msg)
			// 	}
			// })
    },
    appDelete(appId){
      this.$api.apps.appDelete(appId).then((res) => {
				console.log(res);
				this.editLoading = false
				if(res.code == 200) {
          this.deleteOk();
          this.$message({message: '卸载应用完成', type: 'success'})
				} else {
					this.$message({message: '卸载应用失败, ' + res.msg, type: 'error'})
				}
			})
    }
  }
};
</script>

<style scoped lang="scss">
.card-img {
  position: relative;
  height: 110px;
  line-height: 110px;
}
.card-img img {
  max-width: 100%;
  max-height: 100px;
  vertical-align: middle;
}
.card-img>div {
  background: #000;
  opacity: 0;
  position: absolute;
  width: 100%;
  height: 100%;
  top: 0;
}
.card-img>div:hover {
  opacity: 0.1;
}
.card-info {
  padding-top: 10px;
  margin: 10px 15px;
  border-top: 2px solid #e8e8e8;
}
.card-info .el-button {
  text-align: left;
}
.card-info+.el-button {
  border-radius: unset;
}
.title {
  color: #333;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding: 5px 0;
}
.title:hover {
  color: #00afca;
}
.category {
  font-size: 0.6rem;
  color: #BBB;
  margin-top: 3px;
  margin-bottom: 10px;
  height: 20px;
  line-height: 20px;
}
.version .el-button {
  float: right;
  padding: 5px 15px;
  width: unset!important;
}
.version {
  font-size: 0.6rem;
  color: #666;
  line-height: 24px;
}
.category .el-tag {
  float: right;
}
.card-container {
  clear: both;
  padding: 10px;
}
.card {
  margin-bottom: 30px;
  text-align: left;
  background: #fafafa;
}
.text-btn {
  padding: 0;
  border: none;
}
.el-card__body .el-button {
  width: 100%;
}
@media only screen and (min-width: 1600px) {
  .cc {
      width: 16.66667%;
  }
}
@media only screen and (min-width: 2200px) {
  .cc {
      width: 12.5%;
  }
}
</style>
